fn main() {
    println!("hello,world");
    println!("hello,world2");
    let name = String::from("peter");
    let age = 12;
    let peter = Person { name, age };
    println!("{:?}", "hello");
    println!("{:?}", peter);
    let point: Point = Point { x: 10.3, y: 0.4 };

    let bottom_right = Point { x: 15.2, ..point };
    println!("second point: ( {}, {}) ", bottom_right.y, bottom_right.y);
    let Point {
        x: left_edge,
        y: top_edge,
    } = point;
    let _rectangle = Rectangle {
        top_left: Point {
            x: left_edge,
            y: top_edge,
        },
        bottom_right,
    };

    let _unit = Unit;
    let pair = Pair(1, 0.3);
    println!("pair contains {:?} and {:?}", pair.0, pair.1);
    let Pair(integer, decimal) = pair;
    println!("pair contains {:?} and {:?}", integer, decimal);
    //  试一试1
    let Rectangle {
        top_left: Point {
            x: left_edge,
            y: top_edge,
        },
        bottom_right: Point {
            y: _,
            x: bottom_edge,
        },
    } = _rectangle;
    let r3 = Rectangle {
        top_left: Point {
            x: left_edge,
            y: top_edge,
        },
        bottom_right: Point {
            x: bottom_edge,
            y: 20.0,
        },
    };
    println!("面积={:?},{}", r3, r3.rect_area());

    //试一试2
    println!("rectangle={:?}", r3.square(Point { x: 2.0, y: 32.0 }, 30.0));
}
#[derive(Debug)]
#[allow(dead_code)]
struct Person {
    name: String,
    age: u8,
}
struct Unit;

struct Pair(i32, f32);
#[derive(Debug)]
struct Point {
    x: f32,
    y: f32,
}
#[allow(dead_code)]
#[derive(Debug)]
struct Rectangle {
    top_left: Point,
    bottom_right: Point,
}
/** 动手试一试
1. 增加一个计算 Rectangle (⻓方形)面积的函数 rect_area (尝试使用嵌套的解构方 式)。
2. 增加一个函数 square ，接受的参数是一个 Point 和一个 f32 ，并返回一个 Rectangle (⻓方形)，其左上⻆位于该点上，⻓和宽都对应于 f32 。

*/
impl Rectangle {
    fn rect_area(&self) -> f32 {
        (self.bottom_right.x - self.top_left.x) * (self.bottom_right.y - self.top_left.y)
    }
}
impl Rectangle {
    fn square(self, p: Point, num: f32) -> Rectangle {
        Rectangle {
            top_left: Point { ..p },
            bottom_right: Point {
                x: p.x + num,
                y: p.y + num,
            },
        }
    }
}
#[allow(dead_code)]
struct Cat {
    height: i32,
    age: i32,
}
